//
//  ECOrderMainTopEditCollectionViewCell.m
//  ECERP.CRM
//
//  Created by 刘思麟 on 2018/11/19.
//  Copyright © 2018 Mac. All rights reserved.
//

#import "ECOrderMainTopEditCollectionViewCell.h"

@interface ECOrderMainTopEditCollectionViewCell()

@property (nonatomic,strong) ECButton * topRightBT;

@end

@implementation ECOrderMainTopEditCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self setupUI];
    }
    return self;
}

- (void)prepareForReuse {
    [super prepareForReuse];
    self.cellStyle = ECOrderMainTopEditCollectionViewCellStyleDelete;
}

- (void)setupUI {
    WS(weakSelf, self);
    self.contentView.backgroundColor = ECCOLOR(0xF6F6F6);
    self.button = [ECButton buttonWithType:UIButtonTypeCustom];
    self.button.userInteractionEnabled = NO;
    self.button.imgLocation = ECButonImageLocationTop;
    self.button.splitBetweenImgAndTitle = 2 * PX_RELATIVE375;
    [self.contentView addSubview:self.button];
    [self.button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(UIEdgeInsetsZero);
    }];
    
    self.topRightBT = [ECButton buttonWithType:UIButtonTypeCustom];
    [self.contentView addSubview:self.topRightBT];
    [self.topRightBT setTitle:@"" forState:UIControlStateNormal];
    [self.topRightBT addTarget:self action:@selector(doAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.topRightBT mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.right.mas_equalTo(weakSelf.contentView);
        make.width.height.mas_equalTo(24 * PX_RELATIVE375);
    }];
}

- (void)doAction:(ECButton*)sender {
    if (self.doActionBlock) {
        self.doActionBlock(self);
    }
}

- (void)setCellStyle:(ECOrderMainTopEditCollectionViewCellStyle)cellStyle {
    _cellStyle = cellStyle;
    switch (_cellStyle) {
        case ECOrderMainTopEditCollectionViewCellStyleDelete:
            {
                [self.topRightBT setImage:[[UIImage imageWithColor:[UIColor redColor]] imageByResizeToSize:CGSizeMake(24, 24)] forState:UIControlStateNormal];
            }
            break;
        case ECOrderMainTopEditCollectionViewCellStyleAdd:{
            [self.topRightBT setImage:[[UIImage imageWithColor:[UIColor greenColor]] imageByResizeToSize:CGSizeMake(24, 24)] forState:UIControlStateNormal];
        }
            break;
        default:
            break;
    }
}

@end
